package www.wxwnb.clerk.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import www.wxwnb.clerk.R;
import www.wxwnb.clerk.bean.AlreadyCheckBean;
import www.wxwnb.clerk.ui.activity.ContentActivity;
import www.wxwnb.clerk.utils.TimeUtil;

/**
 * Created by lenovo on 2017/9/9.
 */

public class AlreadyCheckedAdapter extends RecyclerView.Adapter<AlreadyCheckedAdapter.MyViewHolder> {

    private Context context;
    private List<AlreadyCheckBean.DataBean.PageRecordsBean> beanList;
    private int type;
    public AlreadyCheckedAdapter(Context context, List<AlreadyCheckBean.DataBean.PageRecordsBean> beanList, int i) {
        this.context=context;
        this.beanList=beanList;
        this.type=i;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=LayoutInflater.from(context).inflate(R.layout.recycler_item,null);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        if(type==0){
            holder.txt_check.setText("已审核");
        }else if(type==1){
            holder.txt_check.setTextColor(Color.parseColor("#f32a2a"));
            holder.txt_check.setText("未审核");
        }else {
            holder.txt_check.setTextColor(Color.parseColor("#f32a2a"));
            holder.txt_check.setText("未通过");
        }

         holder.txt_title.setText(beanList.get(position).getUserName());
        long createTime = beanList.get(position).getCreateTime();
        final String timestamp = TimeUtil.timestamp2DateOrString(createTime);
         holder.txt_time.setText("提交时间: "+timestamp);
         holder.txt_money.setText("开户金额: ¥"+beanList.get(position).getMonery());


         holder.mLinearLayout.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View view) {
                 Intent in=new Intent(context,ContentActivity.class);
                 in.putExtra("name",beanList.get(position).getLoginName());
                 in.putExtra("time",timestamp);
                 in.putExtra("iml",beanList.get(position).getLicenseImage());
                 in.putExtra("imo",beanList.get(position).getOtherImage());
                 in.putExtra("phone",beanList.get(position).getPhone());
                 in.putExtra("money",beanList.get(position).getMonery());
                 in.putExtra("bus",beanList.get(position).getParentChief());
                 in.putExtra("user",beanList.get(position).getUserName());
                 in.putExtra("address",beanList.get(position).getAddress());
                 in.putExtra("type",beanList.get(position).getType());
                 if(beanList.get(position).getAccountImage()!=null){
                     in.putExtra("imz",beanList.get(position).getAccountImage());
                 }

                 if(beanList.get(position).getRemark()!=null){
                     in.putExtra("remark",beanList.get(position).getRemark());
                 }

                 Log.i("nnnn",beanList.get(position).getLoginName()+beanList.get(position).getParentChief()+"..");
                 context.startActivity(in);

             }
         });
    }

    @Override
    public int getItemCount() {
        return beanList==null?0:beanList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder{

        private final TextView txt_check;
        private final TextView txt_money;
        private final TextView txt_time;
        private final TextView txt_title;
        private final LinearLayout mLinearLayout;


        public MyViewHolder(View itemView) {
            super(itemView);
            txt_check = (TextView) itemView.findViewById(R.id.txt_checked_item);
            txt_money = (TextView) itemView.findViewById(R.id.txt_money_item);
            txt_time = (TextView) itemView.findViewById(R.id.txt_time_item);
            txt_title = (TextView) itemView.findViewById(R.id.txt_title_item);
            mLinearLayout = itemView.findViewById(R.id.linear_recycler);

        }
    }
}
